﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Photocopy.Model;
using Photocopy.Business;

namespace Photocopy
{
    public partial class RebuildTemplate : System.Web.UI.MasterPage
    {
        ProductData pd = new ProductData();
        protected void Page_Load(object sender, EventArgs e)
        {
            RptBestProduct.DataSource = pd.getHotProduct();
            RptBestProduct.DataBind();
            //lbLuotTruyCap.Text = pd.GetPageView(1).ToString();
            DateTime now = DateTime.Now;
            string time = now.ToString("HH");
            if (Int32.Parse(time) > 6 && Int32.Parse(time) < 22)
            {
                Random rnd = new Random();
                lbNguoiOnl.Text = rnd.Next(1, 25).ToString();
            }
            else
            {
                lbNguoiOnl.Text = "0";
            }

            if(!IsPostBack)
            {
                txtSearch.Attributes.Add("onkeypress", "return clickButton(event,'" + btnSearch.ClientID + "')");
            }

            // Hỗ trợ kỹ thuật
            rpTechniqueSupport.DataSource = pd.getTechniqueSupport();
            rpTechniqueSupport.DataBind();

            rpIdSlide.DataSource = pd.getCustomer();
            rpIdSlide.DataBind();

            rpCustomer.DataSource = pd.getCustomer();
            rpCustomer.DataBind();

        }

        


        // Hàm search --------------
        protected void btnSearch_Click(object sender, EventArgs e)
        {
            string chuoi = txtSearch.Text;
            Session["Search"] = chuoi;
            Response.Redirect("ket-qua-tim-kiem");
        }

        protected void LinkPrint1_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Ricoh";
            Session["Type"] = "Print";
            Response.Redirect("/may-in");
        }

        protected void LinkPrint2_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Sharp";
            Session["Type"] = "Print";
            Response.Redirect("/may-in");
        }

        protected void LinkPrint3_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Canon";
            Session["Type"] = "Print";
            Response.Redirect("/may-in");
        }

        protected void LinkPrint4_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Toshiba";
            Session["Type"] = "Print";
            Response.Redirect("/may-in");
        }

        protected void LinkPhotocopy1_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Ricoh";
            Session["Type"] = "Photocopy";
            Response.Redirect("/may-photocopy");
        }

        protected void LinkPhotocopy2_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Sharp";
            Session["Type"] = "Photocopy";
            Response.Redirect("/may-photocopy");
        }

        protected void LinkPhotocopy3_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Canon";
            Session["Type"] = "Photocopy";
            Response.Redirect("/may-photocopy");
        }

        protected void LinkPhotocopy4_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "Toshiba";
            Session["Type"] = "Photocopy";
            Response.Redirect("/may-photocopy");
        }

        protected void LinkType1_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "0";
            Session["Type"] = "Photocopy";
            Response.Redirect("/may-photocopy");
        }

        protected void LinkType2_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "0";
            Session["Type"] = "Print";
            Response.Redirect("/may-in");
        }

        protected void LinkType3_Click(object sender, EventArgs e)
        {
            Session["Brand"] = "0";
            Session["Type"] = "Scan";
            Response.Redirect("/may-scan");
        }


        //Phiên bản 2
        //protected void RptBestProduct_ItemCommand(object source, RepeaterCommandEventArgs e)
        //{
        //    if (e.CommandName == "GetProductDetail")
        //    {
        //        Label lblsanpham = (Label)e.Item.FindControl("lbSpID");
        //        int SanphamID = Int32.Parse(lblsanpham.Text);
        //        if (pd.CheckSale(SanphamID) == true)
        //        {
        //            Session["sanpham"] = pd.getProductSale(SanphamID);
        //            Response.Redirect("chi-tiet-san-pham/" + SanphamID.ToString());
        //        }
        //        else
        //        {
        //            Session["sanpham"] = pd.getProduct(SanphamID);
        //            Response.Redirect("chi-tiet-san-pham/" + SanphamID.ToString());
        //        }
        //    }
        //}


        //protected void rpTechniqueSupport_ItemCommand(object source, RepeaterCommandEventArgs e)
        //{
        //    switch(e.CommandName)
        //    {
        //        case "Go":
        //            Label lbId = (Label)e.Item.FindControl("lbTechniqueID");
        //            Session["Technique"] = pd.getTechniqueSupportDetail(Int32.Parse(lbId.Text));
        //            Response.Redirect("ho-tro-ky-thuat");
        //            break;
        //    }
        //}

        //--------------------------------------------------------------------------------------------
    }
}